import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiSkillListPage(Base):
    """
    语音训练技能列表

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的返回键
        self.list_back_btn = (By.XPATH, Yomi.RESOURCE_ID.format('ivBack'))

        # 左侧的返回键
        self.list_home_btn = (By.XPATH, Yomi.RESOURCE_ID.format('ivHome'))

        # 列表标题
        self.list_title_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_title"))

        # 添加技能按钮
        self.list_add_skill_btn = (By.XPATH, Yomi.RESOURCE_ID.format("btn_add"))

        # 技能标题名称
        self.list_skill_name_title_text = (By.XPATH, Yomi.skill_name_title_text.format(""))

        # 技能名称
        self.list_skill_name_text = (By.XPATH, Yomi.skill_name_text.format(""))

        # 技能图标
        self.list_skill_icon = (By.XPATH, Yomi.skill_icon.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.list_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.list_home_btn)

    def click_add_skill(self):
        """
        点击添加技能页

        :return:None
        """
        self.click_element(self.list_add_skill_btn)

    def get_title(self):
        """
        获取列表标题

        :return:获取元素
        """
        return self.find_element_o(self.list_title_text)

    def get_skill_name_title(self, index=1):
        """
        获取技能标题名称

        :return:获取元素
        """
        self.list_skill_name_title_text = (By.XPATH, Yomi.skill_name_title_text.format(index))
        return self.find_element_o(self.list_skill_name_title_text)

    def click_skill_name_title(self, index=1):
        """
        点击技能标题名称

        :return:获取元素
        """
        self.list_skill_name_title_text = (By.XPATH, Yomi.skill_name_title_text.format(index))
        self.click_element(self.list_skill_name_title_text)

    def get_skill_name(self, index=1):
        """
        获取技能名称

        :return:获取元素
        """
        self.list_skill_name_text = (By.XPATH, Yomi.skill_name_text.format(index))
        return self.find_element_o(self.list_skill_name_text)

    def get_skill(self, index=4):
        """
        获取第一个技能图标

        :return:获取元素
        """
        self.list_skill_icon = (By.XPATH, Yomi.skill_icon.format(index))
        return self.find_element_o(self.list_skill_name_text)

    def swipe_radio_list(self):
        """
        滑动城市列表

        :return:None
        """
        self.swipe_o(location=(300, 1500, 200, 200), direction='left')

    def is_display_yomi_skill_list(self):
        """
        查看是否进入技能列表

        :return:
        """
        return self.is_display(self.list_add_skill_btn)
